home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / rsxwdk2s.zip / RSXWDK / LIBSRC / SYSDJ / FSTAT.C < prev    next >
C/C++ Source or Header  |  1994-10-18  |  1KB  |  45 lines

  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <sys/dostime.h>
  4. #include <sys/doscalls.h>
  5.  
  6. #define ACC(x) (((x)>>6)*0111)
  7.  
  8. static long _sys_ino = 0x20000;
  9.  
  10. int fstat (int handle, struct stat *statbuf)
  11. {
  12.     struct file_time ft;
  13.     unsigned long gmt;
  14.     int info;
  15.  
  16.     if ((info = dos_ioctl_getattr(handle)) == -1)
  17.     return -1;
  18.  
  19.     if (!(info & 0x80)) {    /* file */
  20.     long oldpos;
  21.     statbuf->st_mode = S_IFREG;
  22.     oldpos = dos_lseek(handle, 0L, 1);
  23.     statbuf->st_size = dos_lseek(handle, 0L, 2);
  24.     dos_lseek(handle, oldpos, 0);
  25.     statbuf->st_dev = 0;
  26.     } else {            /* device */
  27.     statbuf->st_mode = S_IFCHR;
  28.     statbuf->st_size = 0L;
  29.     statbuf->st_dev = (long) (info & 0x3F);
  30.     }
  31.     dos_getftime(handle, &ft.ft_date, &ft.ft_time);
  32.     gmt = filetime2gmt(&ft);
  33.     statbuf->st_atime = gmt;
  34.     statbuf->st_ctime = gmt;
  35.     statbuf->st_mtime = gmt;
  36.     statbuf->st_mode |= ACC(S_IREAD | S_IWRITE);
  37.     statbuf->st_uid = 0L;
  38.     statbuf->st_gid = 0L;
  39.     statbuf->st_rdev = statbuf->st_dev;
  40.     statbuf->st_nlink = 1L;
  41.     statbuf->st_ino = _sys_ino++;
  42.     statbuf->st_blksize = 4096;
  43.     return 0;
  44. }
  45.